package com.ytktt.study.week12.task11.web;

import com.ytktt.study.week12.task11.MyGateway;
import com.ytktt.study.week12.task11.properties.MqttProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {

    private final MyGateway myGateway;
    private final MqttProperties mqttProperties;

    @PostMapping
    public String send(@RequestBody String message) {
        this.myGateway.sendToMqtt(this.mqttProperties.getTopic(), message);
        return "success";
    }
}
